<!--@ 首页 -->
<template>
	<view class="bg-white" style="min-height: 100vh;" v-if="dataFrom && dataFrom.order">
		<u-notify ref="uNotify" />
		<load-flex :loading="loading" />
		<view class="cu-bar bg-cyan" @click="handleClick" v-if="dataFrom && dataFrom.order">
			<view class="content text-bold">
				{{dataFrom.order.projectTitle}}
			</view>
		</view>
		<view class="u-demo-block__content bg-white solid-bottom" style="z-index: 999;">
			<scroll-view scroll-x class="bg-white nav" v-if="dataFrom.order.orderType ==3">
				<view class="cu-item text-bold " v-model="current" :class="index==current?'text-cyan cur':''"
					v-for="(item,index) in dataOrderTape" :key="index" @tap="TabsList" :data-id="index">
					<view class="flex align-center">
						<!-- <view class="cu-avatar sm round  bg-cyan text-xs"
							>{{index+1}}</view> -->
						{{item}}
					</view>
				</view>
			</scroll-view>
			<scroll-view scroll-x class="bg-white nav" v-else>
				<view class="cu-item text-bold " v-model="current" :class="index==current?'text-cyan cur':''"
					v-for="(item,index) in dataPeriod" :key="index" @tap="TabsList" :data-id="index">
					<view class="flex align-center">
						<!-- <view class="cu-avatar sm round  bg-cyan text-xs"
							>{{index+1}}</view> -->
						{{item}}
					</view>
				</view>
			</scroll-view>
		</view>
		<view v-if="dataFrom.order.orderType ==3">
			<oderType  :ShowAdmin="ShowAdmin" :dataSource='dateOrder' @ok="handeOrde" @center="handeOrde1"  />
		</view>
		<view v-else>
			<uni-card margin="1" :is-shadow="false" padding="0" v-if="current ==0">
				<template v-slot:title>
					<view class="flex text-cyan padding-tb-sm solid-bottom align-center justify-between">
						<view class="text-lg flex align-center">
							<image class="cu-avatar radius10  sm bg-white margin-right-xs" src="../../static/icon/ZY.png" />{{dataFrom.order.createBy}}
						</view>
						<view >
							<view class="text-lg flex align-center">
								<image class="cu-avatar radius10  sm bg-white margin-right-xs" src="../../static/icon/FWS.png" />{{dataFrom.workDetails.length}}条
							</view>

							<!-- <u-line-progress :percentage="dataFrom.order.speedOfProgress" :height="20"
								activeColor="#1CBBB4">
								<text class="u-percentage-slot">{{dataFrom.order.speedOfProgress}}%</text>
							</u-line-progress> -->
						</view>
					</view>
				</template>
			<!-- 	<view class="flex justify-between align-center padding-tb-sm solid-bottom">
					<view class="flex align-center margin-top-xs">
						开始日期：{{dataFrom.order.createTime}}
					</view>
					<view class="flex align-center margin-top-xs">
						结束日期：{{dataFrom.order.orderEndDate}}
					</view>
				</view> -->
			</uni-card>
			<view v-if="current ==1">
				<uni-card :is-shadow="false" margin="0" padding="0">
					<view class="margin-tb-xs">
						<view class="flex justify-between">
							<view @click="handCheck(1)" style="width: 48%;">
								<uni-easyinput v-model="queryParam.orderStartDate" disabled placeholder="请选择开始日期"
									:key="time" />
							</view>
							<view @click="handCheck(2)" style="width: 48%;">
								<uni-easyinput disabled v-model="queryParam.orderEndDate" placeholder="请选择结束日期"
									:key="time" />
							</view>
						</view>
					</view>
					<view slot="actions" class="card-actions">
						<view class="card-actions-item" @click="handeReload">
							<uni-icons type="reload" size="18" color="red"></uni-icons>
							<text class="card-actions-item-text " style="color:red">重置</text>
						</view>
						<view class="card-actions-item" @click="bmsDailyNewOrderList()">
							<uni-icons type="search" size="18" color="#0081ff"></uni-icons>
							<text class="card-actions-item-text " style="color:#0081ff">查询</text>
						</view>
					</view>
				</uni-card>
			</view>
			<manufacture :ShowAdmin="ShowAdmin" :dataFrom="dataFrom" v-if="current ==0" @ok="loadData" />
			<progressFrom :dataFrom="dataFrom" :ShowAdmin="ShowAdmin" :dataSource='NewOrderList' v-if="current ==1"
				@ok="bmsDailyNewOrderList" />
			<page-pagination class="test-pagination" :numAround="true" :total="total" v-if="current ==1"
				layout="page,prev,next,limit,total" :pageSizes="[10,50,60,100]" :currentPage="ipagination.pageNo"
				:pageSize="ipagination.pageSize">
			</page-pagination>
			<myProblem :ShowAdmin="ShowAdmin" :dataSource='ProblemList' v-if="current ==2" @ok="handeProblem" @center="handeProblem1" />
			<ShowAdmin ref="adminFrom" @ok="handeAdmin" />
			<uni-calendar ref="calendar" :insert="false" @confirm="ConfirmCheck" />
		</view>
	</view>
</template>
<script>
	import loadFlex from '@/components/loadFlex/loadFlex.vue' //加载
	import ShowAdmin from '@/components/ShowAdmin.vue' //密码
	import manufacture from '@/components/lopSchedule2/manufacture.vue' //工作内容
	import progressFrom from '@/components/lopSchedule2/progressFrom.vue' //个人日报
	import myProblem from '@/components/lopSchedule2/myProblem.vue' //我的问题
	import oderType from '@/components/lopSchedule2/oderType.vue' //使用教程
	import myApi from '@/utils/app.js' //调用接口使
	export default {
		name: 'lopSchedule2',
		components: {
			loadFlex,
			ShowAdmin,
			manufacture,
			progressFrom,
			myProblem,
			oderType
		},
		data() {
			return {
				loading: false,
				dataPeriod: ['软件开发维护记录', '软件进度', '项目教程', '知识库'],
				dataOrderTape: ['使用教程'],
				tableData: [],
				// 每页数据
				ipagination: {
					pageNo: 1,
					pageSize: 10,
				},
				queryParam: {},
				// 数据总量
				total: 0,
				dataIndex: 0,
				current: 0,
				model: {},
				dataFrom: {},
				NewOrderList: [],
				ProblemList: {},
				clickCount: 0,
				time: '',
				timeoutId: null,
				ShowAdmin: false,
				dateOrder:{},//等于3
			}
		},
		onLoad() {
			 const local = window.location.href
			// const local = 'http://szrswms.com/#/pages/lopSchedule/lopSchedule?id=XM1848016204699144191'
			this.model.mainId = local.match(/id=([^?&]+)/)[1];
			const currentDate = new Date();
			// 格式化今天的日期
			const todayYear = currentDate.getFullYear();
			const todayMonth = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要加 1
			const todayDay = String(currentDate.getDate()).padStart(2, '0');
			this.queryParam.orderEndDate = `${todayYear}-${todayMonth}-${todayDay}`;

			// 获取今天往前推 30 天的日期
			const pastDate = new Date(currentDate);
			pastDate.setDate(currentDate.getDate() - 30);
			const pastYear = pastDate.getFullYear();
			const pastMonth = String(pastDate.getMonth() + 1).padStart(2, '0');
			const pastDay = String(pastDate.getDate()).padStart(2, '0');
			this.queryParam.orderStartDate = `${pastYear}-${pastMonth}-${pastDay}`;
			this.loadData()
		},
		methods: {
			async loadData(index) {
				this.loading = true
				try {
					const res = await this.$request({
						url: myApi.queryById,
						method: 'get',
						data: {
							id: this.model.mainId
						},
					});
					
					if (res.code == 200) {
						
						this.dataFrom = res.result
						
						// for (let i = 0; i < 100; i++) {
						//   this.dataFrom.workDetails.push(this.dataFrom.workDetails[0]);
						// }
						if(this.dataFrom.order.orderType ==3) this.handeOrde()
						if (index == 1) this.onNotify({
							message: '操作成功'
						})
					}
				} catch (e) {
					// 失败执行

				} finally {
					// 销毁执行
					this.loading = false
				}
			},
			async bmsDailyNewOrderList(index) {
				this.loading = true
				try {
					const res = await this.$request({
						url: myApi.bmsDailyNewOrderList,
						method: 'get',
						data: {
							projectNo: this.model.mainId,
							...this.ipagination,
							...this.queryParam
						},
					});
					console.log(res)
					if (res.code == 200) {
						this.NewOrderList = res.result.records
						this.total = res.result.total
						if (index == 1) this.onNotify({
							message: '操作成功'
						})
					}
				} catch (e) {
					// 失败执行

				} finally {
					// 销毁执行
					this.loading = false
				}
			},
			async handeProblem(index,center) { //我的问题
				this.loading = true
				try {
					const res = await this.$request({
						url: myApi.queryProblemById,
						method: 'get',
						data: {
							id: this.model.mainId,
							...this.ipagination,
							content:center?center:''
						},
					});
					console.log(res)
					if (res.code == 200) {
						this.ProblemList = res.result
						if (index == 1) this.onNotify({
							message: '操作成功'
						})
					}
				} catch (e) {
					// 失败执行

				} finally {
					// 销毁执行
					this.loading = false
				}
			},
			handeProblem1(center){
				this.handeProblem(1,center)
			},
			onNotify(round) {
				this.$refs.uNotify.show({
					type: round.type ? round.type : 'success',
					message: round.message ? round.message : '删除成功',
					top: 50
				})
			},

			handleClick() {
				this.clickCount++;
				// 清除之前的定时器
				if (this.timeoutId) {
					clearTimeout(this.timeoutId);
				}
				// 如果点击次数达到3次，触发方法
				if (this.clickCount === 3) {
					if (this.ShowAdmin) this.ShowAdmin = false
					else this.$refs.adminFrom.OnAdemin()
					this.clickCount = 0; // 重置计数器
				} else {
					// 设置一个新的定时器，在1秒后重置计数器
					this.timeoutId = setTimeout(() => {
						this.clickCount = 0;
					}, 1000); // 1000毫秒内没有再次点击则重置计数器
				}
			},
			// 密码
			handeAdmin() {
				this.ShowAdmin = true
			},
			TabsList(e) {
				this.current = e.currentTarget.dataset.id
				this.ipagination.pageNo = 1
				this.ipagination.pageSize = 10
				if (this.current == 0) this.loadData()
				if (this.current == 1) this.bmsDailyNewOrderList()
				if (this.current == 2) this.handeProblem()
			},
			handCheck(index) {
				this.dataIndex = index
				this.$refs.calendar.open();
			},
			ConfirmCheck(e) { // 选择完日期返回过的值
				if (this.dataIndex == 1) this.$set(this.queryParam, 'orderStartDate', e
					.fulldate);
				if (this.dataIndex == 2) this.$set(this.queryParam, 'orderEndDate', e
					.fulldate);
				this.time = new Date().valueOf()
			},
			handeReload() {
				this.ipagination.pageNo = 1
				this.ipagination.pageSize = 10
				this.queryParam = {}
				const currentDate = new Date();
				// 格式化今天的日期
				const todayYear = currentDate.getFullYear();
				const todayMonth = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要加 1
				const todayDay = String(currentDate.getDate()).padStart(2, '0');
				this.queryParam.orderEndDate = `${todayYear}-${todayMonth}-${todayDay}`;
				// 获取今天往前推 30 天的日期
				const pastDate = new Date(currentDate);
				pastDate.setDate(currentDate.getDate() - 30);
				const pastYear = pastDate.getFullYear();
				const pastMonth = String(pastDate.getMonth() + 1).padStart(2, '0');
				const pastDay = String(pastDate.getDate()).padStart(2, '0');
				this.queryParam.orderStartDate = `${pastYear}-${pastMonth}-${pastDay}`;
				this.bmsDailyNewOrderList(1)
			},
		async handeOrde(index,center){
				this.loading = true
				try {
					const res = await this.$request({
						url: myApi.queryProblemById,
						method: 'get',
						data: {
							id: this.model.mainId,
							...this.ipagination,
							content:center?center:''
						},
					});
					console.log(res)
					if (res.code == 200) {
						this.dateOrder= res.result
						if (index == 1) this.onNotify({
							message: '操作成功'
						})
					}
				} catch (e) {
					// 失败执行
				
				} finally {
					// 销毁执行
					this.loading = false
				}
			},
			handeOrde1(center){
				this.handeOrde(1,center)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		background-color: #CBEDED;
	}

	::v-deep .is-disabled {
		background-color: #ffffff !important;
		color: #0d0d0d !important;
		pointer-events: none
	}
</style>